<template>
  <div>
    <el-dialog :visible="visible" width="50%" @close="handleClose" :close-on-click-modal="false"
      :close-on-press-escape="false" title="非一物一码批量打印">
      <!-- 这里可以放置对话框内部的内容 -->
      <el-row :gutter="15">
        <el-form ref="elForm" :model="formData" size="medium" label-width="120px" :rules="rules" label-position="right">
          <el-col :span="12">
            <el-form-item label="模板选择" prop="temp">
              <el-select v-model="formData.temp" clearable :style="{ width: '100%' }">
                <el-option v-for="(item, index) in tempList" :key="index" :label="item.label"
                  :value="item.value"></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="物料代码映射" prop="finallyCode">
              <el-radio-group v-model="formData.finallyCode">
                <el-radio label="1">供应商代码</el-radio>
                <el-radio label="2">GMP码</el-radio>
              </el-radio-group>
            </el-form-item>
          </el-col>
          <el-col :span="24" style=" display: flex; justify-content: flex-end;">
            <el-form-item size="large">
              <el-button type="primary" @click="submitPrint">打印</el-button>
              <el-button @click="handleClose">取消</el-button>
            </el-form-item>
          </el-col>
        </el-form>
      </el-row>
    </el-dialog>
    <goodsPrint v-show="false" ref="buyIndexRef"></goodsPrint>
  </div>
</template>

<script>
  import goodsPrint from '@/views/basic/print/printList/print.vue'
  export default {
    data() {
      return {
        printData: {}, //拿到当前行的数据
        formData: {
          temp: '', //打印模板
          finallyCode: '',
        },
        tempList: [{
          value: 'commercialize',
          label: '物料标签(商业化物料)',
        }, {
          value: 'noCommercialize1',
          label: '物料标签(非商业化第1类)',
        }, {
          value: 'noCommercialize2',
          label: '物料标签(非商业化第2类)',
        }, {
          value: 'psyCommercialize',
          label: '物料精神药品标签(商业化)',
        }, {
          value: 'verification',
          label: '物料精神药品标签(验证阶段)',
        }, {
          value: 'experimental',
          label: '物料精神药品标签(试验开发阶段)',
        }, {
          value: 'boffin',
          label: '物料标签(研究院)',
        }, {
          value: 'productBiaoQ',
          label: '低耗备件标签'
        }, {
          value: 'sampleInstitute',
          label: '样品标签(研究院)',
        }, {
          value: 'productSample1',
          label: '精神商业化产品标签',
        }, {
          value: 'productSample2',
          label: '精神验证阶段产品标签',
        }, {
          value: 'productSample3',
          label: '精神试用开发产品标签',
        }, {
          value: 'productSample',
          label: '中间产品',
        }, {
          value: 'productSampleNew',
          label: '非商业化产品标签',
        }, {
          value: 'importantTip',
          label: '试剂/关键耗材标签'
        }], //模板选择
        rules: {
          finallyCode: [{
            required: true,
            message: '映射不能为空',
            trigger: 'change',
          }],
          temp: [{
            required: true,
            message: '模板不能为空',
            trigger: 'change',
          }],
        },
      }
    },
    components:{
      goodsPrint
    },
    props: ['visible'],
    methods: {
      openDialog(row) {
        this.printData = row;
      },
      // 提取重置表单的逻辑
      handleClose() {
        this.$nextTick(() => {
          this.$refs.elForm.resetFields();
        })
        // 通过事件通知父组件更新visible值，触发update:visible事件
        this.$emit('update:visible', false);
      },
      //打印标签
      submitPrint() {
        this.$refs.elForm.validate((valid) => {
          if (!valid) {
            return; // 验证不通过直接返回
          }
          let tips = '是否确认打印？';
          this.$confirm(tips, '提示', {
            confirmButtonText: '确定',
            cancelButtonText: '取消',
            type: 'warning'
          }).then(() => {
            this.$refs.buyIndexRef.morePrintCode(this.formData.temp,this.formData.finallyCode,this.printData);
            this.handleClose();
          }).catch(() => {});
        });
      }
    }
  }
</script>

<style>
</style>
